'use strict';
module.exports = {
	/**
	 * 此函数名称
	 * @url client/user/pub/test 前端调用的url参数地址
	 * data 请求参数
	 * @params {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, originalParam
		} = event;
		let {
			customUtil,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			number,
			car_id,
			merchandise_id,
			car_inventory
		} = data;
		let res = {
			code: 0,
			msg: ''
		};
		// 业务逻辑开始-----------------------------------------------------------
		// 可写与数据库的交互逻辑等等
		console.log("草泥马",data)
		let product_info = await vk.baseDao.findById({
			dbName: "daoju_merchandise",
			id:merchandise_id
		})
		
		// car_current.inventory 
		let car_number = car_inventory || 0
		
		if(number  > product_info.inventory){
		
			return {
				msg:"商品加购件大于库存",
				code:-1
			}
		}
		
		
		console.log('car_id',car_id)
		await vk.baseDao.updateById({
		  dbName: "daoju_shopcart",
		  id: car_id,
		  dataJson: {
		    number: number
		  },
		});

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}